<?php

namespace app\pc\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


// 修改交易密码
class Passwd extends Base
{
    public  $model;
    public function __construct()
    {
        $this->model = model("UsersMoney");
        parent::__construct();
        $this->BaseWhere = ['a.user_id'=>$this->sidRows['id']];
        $this->BaseWhereNoa = ['user_id'=>$this->sidRows['id']];
    }


    /**
     *  修改交易密码
     */
    public function  modification(){

        $count = $this->model->baseCount($this->BaseWhereNoa);
        if(!$count){
                return failJson("请先设置交易密码");
        }

       $code =  Cache::get($this->sidRows['mobile']."code");
        if(!$code){
            return failJson("请发送验证码");
        }
        if($code!=$this->code){
            return failJson("验证码不正确");
        }
        $transact_password = $this->transact_password;
        $ealt = rand(1000,9000);
        $data = [
            "transact_password"=>md5($this->transact_password.$ealt),
            "ealt"=>$ealt,
        ];
        $res = $this->model->save($data,$this->BaseWhereNoa);
        if(empty($res)){
                return failJson("修改交易密码失败");
        }
        return sucessJson("修改交易密码成功");


    }


    /**
     *  修改交易密码
     */
    public function  setpd(){

        $code =  Cache::get($this->sidRows['mobile']."code");
        $count = $this->model->baseCount($this->BaseWhereNoa);
        if($count){
            return failJson("你已经设置了交易密码");
        }

        if(!$code){
            return failJson("请发送验证码");
        }
        if($code!=$this->code){
            return failJson("验证码不正确");
        }


        $ealt = rand(1000,9000);
        $data = [
            "transact_password"=>md5($this->transact_password.$ealt),
            "ealt"=>$ealt,
            "user_id"=>$this->sidRows['id'],
        ];
        $res = $this->model->save($data);
        if(empty($res)){
            return failJson("设置交易密码失败");
        }
        return sucessJson("设置交易密码成功");


    }

    public function  verify(){

        $code =  Cache::get($this->sidRows['mobile']."code");


        if(!$code){
            return failJson("请发送验证码");
        }
        if($code!=$this->code){
            return failJson("验证码不正确");
        }
        return sucessJson("验证码正确");


    }




}
